<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">

            <!-- 放置表单 -->
            <el-form :model="userInfoForm" :rules="rules" label-width="120px" style="margin-left: 120px; margin-top:30px">
              <el-form-item prop="username" label="姓名:">
                <el-input v-model="userInfoForm.username" style="width:300px" />
              </el-form-item>
              <el-form-item prop="password2" label="密码:">
                <el-input v-model="userInfoForm.password2" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="updateInfo">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <component :is="UserDetail" />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <component :is="JobPostInfo" />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getAvatarAPI, updateInfoAPI } from '@/api'
import UserDetail from '../components/UserDetail.vue'
import JobPostInfo from '../components/JobPostInfo.vue'
export default {
  components: {
    UserDetail,
    JobPostInfo
  },
  props: {
    id: {
      type: [Number, String],
      required: true
    }
  },
  data() {
    return {
      JobPostInfo: 'JobPostInfo',
      UserDetail: 'UserDetail',
      userInfoForm: {
        username: '',
        password2: ''
      },
      rules: {
        username: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
        password2: [{ required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 9, message: '密码长度6-9位', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.getUserInfo()
  },
  methods: {
    async getUserInfo() {
      try {
        this.userInfoForm = await getAvatarAPI(this.id)
      } catch (err) {
        console.log(err)
      }
    },
    async updateInfo() {
      await updateInfoAPI({ ...this.userInfoForm, password: this.updateInfo.password2 })
      this.$message.success('更新成功')
    }
  }
}
</script>

<style>

</style>
